import { http } from ".";
import type { ResultInter, UserInter } from "../types/systemInstance";
import { setCookie } from "../utils/cookies";
// 拿到通知列表
export async function getAnnouncementList() {
    try {
        let response = await http.get("/system/visitor/annoucements")
        return response.data.list
    } catch (error) {
        throw new Error(`获取公告列表失败: ${error}`)
    }
}

// 登录接口
export async function login(user: UserInter): Promise<ResultInter> {
    try {
        let response = <ResultInter>await http.post('/auth/visitor/login', user);
        if (response.code === 200) {
            // 登录成功保存cookie信息
            setCookie("briefblog_token", response.data.token, 1)
        }
        return response
    } catch (error) {
        throw new Error(`登录失败: ${error}`)
    }
}
